import QtQuick 1.1
import "Modulelib.js" as ModuleUtil
import "CommomUtil.js" as Util

ListModel{
    id: listModel

    property int pageIndex: 1

    property int pageSize: 50

    function getData(){
        Util.getXmlStringByUrl(ModuleUtil.getVehiclesListUrl(listModel.pageIndex,listModel.pageSize),callback);
    }

    function callback(responseXml){
        var a = responseXml.documentElement;
        var preFacName = ""; var curretName = "";
        var id = 0; var name = ""; var img = ""; var number = ""; var facName = ""; var backType = "";
        for(var i = 0; i < a.childNodes[1].childNodes.length; ++i){
            if(a.childNodes[1].childNodes[i] !== null && a.childNodes[1].childNodes[i].childNodes.length > 4){
                curretName = a.childNodes[1].childNodes[i].childNodes[3].childNodes[0].nodeValue;
                  if(id != 0 && preFacName !== ""){// 跳过初始值
                    if(curretName !== preFacName){
                        backType = "bottom";
                    }
                    listModel.append({"backType": backType, "Type":"item","titleName":facName,"vehName":name,"vehNum":number,"img":img,"id":id});
                    if(backType === "top"){
                        backType = "mid";
                    }
                }
                if(preFacName === "" || curretName !== preFacName){// 厂商名称不同
                    listModel.append({"backType": "", "Type":"title","titleName":curretName,"vehName":"","vehNum":0,"img":"","id":0});
                    preFacName = curretName;
                    backType = "top";
                }

                id = a.childNodes[1].childNodes[i].childNodes[0].childNodes[0].nodeValue;
                name = a.childNodes[1].childNodes[i].childNodes[1].childNodes[0].nodeValue;
                img = a.childNodes[1].childNodes[i].childNodes[4].childNodes[0].nodeValue;
                number = a.childNodes[1].childNodes[i].childNodes[5].childNodes[0].nodeValue;
                facName = curretName;
            }
        }
        // 加上最后一列
        listModel.append({"backType": "bottom", "Type":"item","titleName":facName,"vehName":name,"vehNum":number,"img":img,"id":id});
        loading.finish();
    }
}
